﻿using System;

namespace XamlInspector.Foundation
{
    public class EventArgs<T> : EventArgs
    {
        public EventArgs()
        {
            
        }

        public EventArgs(T data)
        {
            Data = data;
        }

        public T Data { get; private set; }
    }

    public static class EventExtensions
    {
        public static void Fire(this EventHandler handler, object sender, EventArgs args)
        {
            if( handler != null)
            {
                handler(sender, args);
            }
        }

        public static void Fire(this EventHandler handler, object sender)
        {
            if (handler != null)
            {
                handler(sender, EventArgs.Empty);
            }
        }

        public static void Fire<T>(this EventHandler<EventArgs<T>> handler, object sender, T data)
        {
            if (handler != null)
            {
                handler(sender, new EventArgs<T>(data));
            }
        }
    }
}
